const { log } = require('console');
const fs = require('fs');
const path = require('path');
const dirname = path.resolve(__dirname, './myFile/3')




// 判斷件夹是否存在
async function exists() {
    try {
        await fs.promises.stat(dirname)
        log('文件夹存在')
        return true
    }
    catch (e) {
        log(e)
        if (e.code === 'ENOENT'){
            log('文件夹不存在')
            return false
        }
        throw e
    }
}
// 创建文件夹
async function test() {
    const isExists = await exists()
    if (isExists) {
        log('文件夹存在')
    } else {
        await fs.promises.mkdir(dirname)
        log('mkdir success 创建文件夹成功')
    }
 }
test()